package com.example.query;

import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.Data;

@Data
public class PageQuery {
    // 页码
    private Integer currentPage = 1;
    // 页数
    private Integer pageSize = 10;
    // 排序字段
    private String sortBy;
    // 是否降序
    private Boolean isAsc = true;


    public <T> Page<T> toMpPage(OrderItem ... items){
        Page<T> page = Page.of(currentPage, pageSize);
        if(sortBy != null){
            OrderItem orderItem = new OrderItem();
            orderItem.setColumn(sortBy);
            orderItem.setAsc(isAsc);
            page.addOrder(orderItem);
        }
        else if(items != null){
            page.addOrder(items);
        }
        return page;
    }

    public <T> Page<T> toMpPage(String SortBy,Boolean IsAsc){
        OrderItem orderItem = new OrderItem();
        orderItem.setColumn(SortBy);
        orderItem.setAsc(IsAsc);
        return toMpPage(orderItem);
    }

    public <T> Page<T> toMpPage(String SortBy){
        OrderItem orderItem = new OrderItem();
        orderItem.setColumn(SortBy);
        orderItem.setAsc(isAsc);
        return toMpPage(orderItem);
    }

}
